#!/usr/bin/env python

import voipy.utils

LongNames = {
        "accept" : "Accept",
        "accept-encoding" : "Accept-Encoding",
        "accept-language" : "Accept-Language",
        "alert-info" : "Alert-Info",
        "allow" : "Allow",
        "authentication-info" : "Authentication-Info",
        "authorization" : "Authorization",
        "call-id" : "Call-ID",
        "call-info" : "Call-Info",
        "contact" : "Contact",
        "content-disposition" : "Content-Disposition",
        "content-encoding" : "Content-Encoding",
        "content-language" : "Content-Language",
        "content-length" : "Content-Length",
        "content-type" : "Content-Type",
        "cseq" : "CSeq",
        "date" : "Date",
        "error-info" : "Error-Info",
        "expires" : "Expires",
        "from" : "From",
        "in-reply-to" : "In-Reply-To",
        "max-forwards" : "Max-Forwards",
        "mime-version" : "MIME-Version",
        "min-expires" : "Min-Expires",
        "organization" : "Organization",
        "priority" : "Priority",
        "proxy-authenticate" : "Proxy-Authenticate",
        "proxy-authorization" : "Proxy-Authorization",
        "proxy-require" : "Proxy-Require",
        "record-route" : "Record-Route",
        "reply-to" : "Reply-To",
        "require" : "Require",
        "retry-after" : "Retry-After",
        "route" : "Route",
        "server" : "Server",
        "subject" : "Subject",
        "supported" : "Supported",
        "timestamp" : "Timestamp",
        "to" : "To",
        "unsupported" : "Unsupported",
        "user-agent" : "User-Agent",
        "via" : "Via",
        "warning" : "Warning",
        "www-authenticate" : "WWW-Authenticate",
    }

ShortNames = {
        'i' : 'Call-ID',
        'm' : 'Contact',
        'e' : 'Content-Encoding',
        'l' : 'Content-Length',
        'c' : 'Content-Type',
        'f' : 'From',
        's' : 'Subject',
        'k' : 'Supported',
        't' : 'To',
        'v' : 'Via',
    }

def normalize(name):
    n = name.lower()
    d = len(n) == 1 and ShortNames or LongNames
    if n in d: name = d[n]
    return name

def normalise(name):
    return normalize(name)

class HeaderList(voipy.utils.SymbolicList):
    def _get_obj_name(self, hdr):
        #import headerbases
        #if not issubclass(hdr, headerbases.HeaderBase):
        #    raise Exception, "%r is not a Header object" % hdr
        if not hasattr(hdr, 'name'):
            raise Exception, "Hmmm, seems %r ain't no Header object" % hdr
        return normalize(hdr.name)
